package com.sec.android.app.myfiles.fragment.filelist;

import android.animation.Animator;
import android.animation.Animator.AnimatorListener;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.content.ClipData;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.DragEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.accessibility.AccessibilityEvent;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.sec.android.app.myfiles.R;
import com.sec.android.app.myfiles.activity.GetMoreSpaceActivity;
import com.sec.android.app.myfiles.facade.MyFilesFacade;
import com.sec.android.app.myfiles.facade.cmd.SpinnerProgressCmd;
import com.sec.android.app.myfiles.feature.DragAndDropMgr;
import com.sec.android.app.myfiles.fragment.AbsMyFilesFragment;
import com.sec.android.app.myfiles.info.AppConstants;
import com.sec.android.app.myfiles.info.AppFeatures;
import com.sec.android.app.myfiles.log.Log;
import com.sec.android.app.myfiles.log.SamsungAnalyticsLog;
import com.sec.android.app.myfiles.module.abstraction.FileRecord;
import com.sec.android.app.myfiles.navigation.NavigationInfo;
import com.sec.android.app.myfiles.navigation.NavigationManager;
import com.sec.android.app.myfiles.operation.ProgressListener;
import com.sec.android.app.myfiles.util.StorageMonitor;
import com.sec.android.app.myfiles.util.UiUtils;
import com.sec.android.app.myfiles.util.animation.interpolator.QuintOut80;

import java.util.ArrayList;

public class PathIndicator extends HorizontalScrollView implements View.OnDragListener, ProgressListener {
    private final Context mContext;
    private AbsMyFilesFragment mFragment;

    private final ArrayList<FileRecord> mDisplayedPath = new ArrayList<>();
    private final ArrayList<PathIndicatorHolder> mNavigationItemViewList = new ArrayList<>();
    private final ArrayList<PathIndicatorHolder> mNavigationItemPreviousViewList = new ArrayList<>();

    private NavigationInfo mPreInfo;
    private LinearLayout mNavigationLayout;
    private boolean mIsSplitLandMode = false;
    private ShowState mShowState = ShowState.HIDDEN;

    private LinearLayout mRootPathLayout;

    public enum ShowState {
        SHOW,
        HIDDEN
    }

    public PathIndicator(Context context) {
        super(context);
        mContext = context;
        initializeView();
    }

    public PathIndicator(Context context, AttributeSet attrs) {
        super(context, attrs);
        mContext = context;
        initializeView();
    }

    public PathIndicator(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        mContext = context;
        initializeView();
    }

    private void initializeView() {
        mNavigationLayout = new LinearLayout(mContext);
        addView(mNavigationLayout, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
        this.setFocusable(false);
    }

    public void setFragment(AbsMyFilesFragment fragment) {
        mFragment = fragment;
    }

    @Override
    public void setVisibility(int visibility) {
        super.setVisibility(visibility);

        if (visibility != View.VISIBLE) {
            mPreInfo = null;
        }

        RelativeLayout pathIndicatorContainer = (RelativeLayout) mFragment.getActivity().findViewById(R.id.path_indicator_container);
        pathIndicatorContainer.setVisibility(visibility);
    }

    public void updatePathIndicator(NavigationInfo curInfo) {
        if (this.getVisibility() == View.VISIBLE) {
            FileRecord curRecord = curInfo.getCurRecord();
            boolean isGoingParent = false;
            boolean isDeepIn = true;

            if (mPreInfo != null) {
                FileRecord preRecord = mPreInfo.getCurRecord();
                isGoingParent = isGoingParentPath(preRecord, curRecord);
                isDeepIn = isGoingToDeepIn(preRecord, curRecord);
            }
            clearPath();
            makePathList(curRecord);

            makePathIndicator();
            showPathIndicator(isGoingParent, isDeepIn);

            mPreInfo = curInfo;

            setRootPathView();
            updatePathIndicatorHeight();
        }
    }

    private void updatePathIndicatorHeight() {
        RelativeLayout pathIndicatorContainer = (RelativeLayout) mFragment.getActivity().findViewById(R.id.path_indicator_container);
        pathIndicatorContainer.getLayoutParams().height = getResources().getDimensionPixelSize(R.dimen.path_indicator_height);

        LinearLayout rootPathLayout = (LinearLayout) mFragment.getActivity().findViewById(R.id.path_indicator_root_path);
        rootPathLayout.getLayoutParams().height = getResources().getDimensionPixelSize(R.dimen.path_indicator_height);
    }

    private void clearPath() {
        for (PathIndicatorHolder vh : mNavigationItemViewList) {
            vh.navigationItem.clearAnimation();
        }

        mDisplayedPath.clear();
        mNavigationItemPreviousViewList.clear();
        mNavigationItemPreviousViewList.addAll(mNavigationItemViewList);
        mNavigationItemViewList.clear();
        mNavigationLayout.removeAllViewsInLayout();
    }

    private void makePathList(FileRecord record) {
        FileRecord curRecord = record;
        while (curRecord != null) {
            mDisplayedPath.add(0, curRecord);
            curRecord = curRecord.getParent();
        }
    }

    private void makePathIndicator() {
        NavigationManager naviMgr = NavigationManager.getInstance(mFragment.getProcessId());
        int displayPathSize = mDisplayedPath.size();
        String displayName;

        NavigationInfo curInfo = naviMgr.getCurInfo();
        if (curInfo == null) {
            return;
        }
        for (int curPath = 0; curPath <= displayPathSize; curPath++) {
            PathIndicatorHolder vh = createPathIndicatorHolder();
            if (curPath != 0) {
                vh.pathButton.setTag(curPath - 1);
            }

            if (curPath == 0) {
                vh.pathArrow.setVisibility(View.GONE);

                displayName = getResources().getString(R.string.app_name);
                vh.navigationItem.setVisibility(View.GONE);

                if (curInfo.getNavigationMode() != NavigationInfo.NavigationMode.Select_create_doc_destination) {
                    vh.pathButton.setOnClickListener(mHomeNavigationItemClickListener);
                }
                setPathIndicatorContentDescription(vh, getResources().getString(R.string.app_name));
            } else if (curPath == 1) {
                displayName = mDisplayedPath.get(curPath - 1).getName();
                String fullPath = mDisplayedPath.get(curPath - 1).getFullPath();
                String storageName = StorageMonitor.getDisplayName(mContext, fullPath);
                if (!TextUtils.isEmpty(storageName)) {
                    displayName = storageName;
                }
                vh.pathArrow.setVisibility(View.GONE);
                if (curPath < displayPathSize) {
                    vh.pathButton.setOnClickListener(mNavigationItemClickListener);
                    setPathIndicatorContentDescription(vh, StorageMonitor.getDisplayName(mContext, mDisplayedPath.get(curPath - 1).getFullPath()));
                }
                vh.pathButton.setOnDragListener(this);
            } else {
                displayName = mDisplayedPath.get(curPath - 1).getName();
                vh.pathArrow.setVisibility(View.VISIBLE);
                if (curPath < displayPathSize) {
                    vh.pathButton.setOnClickListener(mNavigationItemClickListener);
                    setPathIndicatorContentDescription(vh, mDisplayedPath.get(curPath - 1).getName());
                }
                vh.pathButton.setOnDragListener(this);
            }
            vh.pathButton.setText(displayName);
            mNavigationItemViewList.add(vh);

            if (curPath != displayPathSize && AppFeatures.isEnableButtonBackgrounds(mContext)) {
                setBtnBackgroundColor(vh.pathButton);
            }
        }
    }

    private PathIndicatorHolder createPathIndicatorHolder() {
        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        PathIndicatorHolder vh = new PathIndicatorHolder();
        if (!AppFeatures.isTabletUIMode()) {
            vh.navigationItem = (LinearLayout) inflater.inflate(R.layout.navigation_view_item_common, null);
        } else {
            vh.navigationItem = (LinearLayout) inflater.inflate(R.layout.navigation_view_item_tablet_common, null);
        }
        vh.pathArrow = (ImageView) vh.navigationItem.findViewById(R.id.list_subtitle_tab_arrow);
        vh.pathButton = (TextView) vh.navigationItem.findViewById(R.id.list_subtitle_tab_item);
        if (AppFeatures.isTabletUIMode() && UiUtils.isInRTLMode(mContext)) {
            vh.pathArrow.setRotation(180);
        }
        return vh;
    }

    private void setPathIndicatorContentDescription(PathIndicatorHolder vh, String name) {
        vh.pathButton.setContentDescription(name + ", " + String.format(getResources().getString(R.string.double_to_go_to_folder), name));
    }

    private boolean needToHideRootPath() {
        boolean bRet = false;
        NavigationManager navigationManager = NavigationManager.getInstance(mFragment.getProcessId());

        NavigationInfo navigationInfo = navigationManager.getCurInfo();
        if (navigationInfo != null) {
            boolean isFromPrivateBox = navigationManager.isFromPrivateBox();
            boolean isFromPrivateStorage = navigationManager.isFromPrivateStorage();
            NavigationInfo.NavigationMode naviMode = navigationInfo.getNavigationMode();
            if (isFromPrivateBox && naviMode == NavigationInfo.NavigationMode.Normal) {
                bRet = true;
            } else if (naviMode == NavigationInfo.NavigationMode.Select_copy_destination ||
                    naviMode == NavigationInfo.NavigationMode.Select_move_destination) {
                if (isFromPrivateBox || isFromPrivateStorage || AppFeatures.isKnox()) {
                    bRet = true;
                }
            } else if (navigationInfo.isPickerMode()) {
                bRet = true;
            }
        }
        return bRet;
    }

    private void setRootPathView() {
        mRootPathLayout = (LinearLayout) mFragment.getActivity().findViewById(R.id.path_indicator_root_path);
        mRootPathLayout.removeAllViewsInLayout();

        if (needToHideRootPath()) {
            mRootPathLayout.setVisibility(View.GONE);
        } else {
            PathIndicatorHolder textViewHolder = createPathIndicatorHolder();
            textViewHolder.pathArrow.setVisibility(View.GONE);
            textViewHolder.pathButton.setText(getResources().getString(R.string.app_name));
            textViewHolder.pathButton.setOnClickListener(mHomeNavigationItemClickListener);
            setPathIndicatorContentDescription(textViewHolder, getResources().getString(R.string.app_name));

            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);

            mRootPathLayout.addView(textViewHolder.navigationItem, lp);

            PathIndicatorHolder arrowViewHolder = createPathIndicatorHolder();
            arrowViewHolder.pathArrow.setVisibility(View.VISIBLE);
            arrowViewHolder.pathButton.setVisibility(View.GONE);

            mRootPathLayout.addView(arrowViewHolder.navigationItem, lp);

            if (AppFeatures.isEnableButtonBackgrounds(mContext)) {
                setBtnBackgroundColor(textViewHolder.pathButton);
            }
        }
    }

    public void updateFocusForKeyboard() {
        if (getVisibility() == View.VISIBLE) {
            PathIndicatorHolder vh = null;
            int size = mNavigationItemViewList.size();
            if (size > 1) {
                vh = mNavigationItemViewList.get(size - 2);
            }
            if (size == 2 && mRootPathLayout != null && mRootPathLayout.getChildAt(0) != null && mRootPathLayout.getVisibility() == View.VISIBLE) {
                mRootPathLayout.getChildAt(0).requestFocus();
            }
            if (UiUtils.isTalkBackEnabled(mContext)) {
                if (vh != null && vh.navigationItem != null) {
                    vh.navigationItem.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
                }
            }
        }
    }

    private void setBtnBackgroundColor(TextView v) {
        if (v != null) {
            int density = (int) getResources().getDisplayMetrics().density;
            v.setBackgroundResource(R.drawable.navigation_path_button);
            v.setPadding(6 * density, 4 * density, 6 * density, 4 * density);
        }
    }

    private void showPathIndicator(boolean isGoingParent, boolean isDeepIn) {
        int size = mNavigationItemViewList.size();

        if (isGoingParent) {
            showParentPath(size);
        } else if (isDeepIn) {
            showDeepInPath(size);
        } else {
            size = mNavigationItemPreviousViewList.size();
            showDeepOutPath(size);
        }
    }

    private void showParentPath(int size) {
        for (int i = 0; i <= size; i++) {
            PathIndicatorHolder vh;
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            if (i < size) {
                vh = mNavigationItemViewList.get(i);
                if (i == size - 1) {
                    setSelectedItemText(vh.pathButton);
                }
                mNavigationLayout.addView(vh.navigationItem, lp);
            } else {
                if (i < mNavigationItemPreviousViewList.size()) {
                    vh = mNavigationItemPreviousViewList.get(i);
                    mNavigationLayout.addView(vh.navigationItem, lp);
                    startAnimation(vh.navigationItem, true, true);
                }
            }
        }
    }

    private void showDeepOutPath(int size) {
        int currentSize = mNavigationItemViewList.size();
        for (int i = 0; i < size; i++) {
            PathIndicatorHolder vh;
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);

            if (i < currentSize) {
                vh = mNavigationItemViewList.get(i);
                mNavigationLayout.addView(vh.navigationItem, lp);
                if (i == currentSize - 1) {
                    setSelectedItemText(vh.pathButton);
                }
            } else {
                vh = mNavigationItemPreviousViewList.get(i);
                mNavigationLayout.addView(vh.navigationItem, lp);
                startAnimation(vh.navigationItem, true, i == currentSize + 1);
            }
        }
    }

    private void showDeepInPath(int size) {
        for (int i = 0; i < size; i++) {
            PathIndicatorHolder vh = mNavigationItemViewList.get(i);
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);

            if (i == size - 1) {
                setSelectedItemText(vh.pathButton);
                startAnimation(vh.navigationItem, false, true);
            }
            mNavigationLayout.addView(vh.navigationItem, lp);
        }
    }

    private void setSelectedItemText(TextView view) {
        Resources res = getResources();
        view.setFocusable(false);
        view.setTextColor(res.getColor(R.color.navigation_view_item_text_selected, null));
        view.setAlpha(0.8f);
        view.setTypeface(AppConstants.FontTypeface.SEC_ROBOTO_LIGHT, Typeface.BOLD);
    }

    private void startAnimation(final View view, final boolean isGoingParent, final boolean canStartSizeOverAnimation) {
        Animation animation = AnimationUtils.loadAnimation(mContext, isGoingParent ? R.anim.navigation_view_slide_out
                : R.anim.navigation_view_slide_in);

        if (animation == null) {
            return;
        }

        animation.setInterpolator(new QuintOut80());
        view.startAnimation(animation);
        animation.setAnimationListener(new AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                if (getWidth() < mNavigationLayout.getWidth() + mNavigationLayout.getWidth() * 2 && canStartSizeOverAnimation) {
                    if (!UiUtils.isInRTLMode(mContext))
                        startSizeOverAnimation(view, isGoingParent);
                }
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                if (isGoingParent) {
                    view.setVisibility(View.GONE);
                } else {
                    view.setVisibility(View.VISIBLE);
                }
            }
        });
    }

    private void startSizeOverAnimation(final View view, final boolean isGoingParent) {
        ObjectAnimator animator;
        int distance;
        if (isGoingParent) {
            if (view.getX() < getWidth() - (int) mNavigationLayout.getX() * 2)
                distance = 0;
            else
                distance = (int) view.getX() - getWidth() + (int) mNavigationLayout.getX() * 2;
            animator = ObjectAnimator.ofInt(this, "scrollX", distance).setDuration(330);
        } else {
            distance = mNavigationLayout.getWidth() - getWidth() + (int) mNavigationLayout.getX() * 2;
            animator = ObjectAnimator.ofInt(this, "scrollX", distance).setDuration(330);
        }
        animator.setInterpolator(new QuintOut80());
        animator.addListener(new AnimatorListener() {

            @Override
            public void onAnimationStart(Animator arg0) {
                // TODO Auto-generated method stub
            }

            @Override
            public void onAnimationRepeat(Animator arg0) {
                // TODO Auto-generated method stub
            }

            @Override
            public void onAnimationEnd(Animator arg0) {
                // TODO Auto-generated method stub
                if (isGoingParent) {
                    view.setVisibility(View.GONE);
                } else {
                    view.setVisibility(View.VISIBLE);
                }
            }

            @Override
            public void onAnimationCancel(Animator arg0) {
                // TODO Auto-generated method stub
            }
        });
        animator.start();
    }

    public void setShowState(ShowState showState) {
        mShowState = showState;
    }

    public ShowState getShowState() {
        return mShowState;
    }

    private static class PathIndicatorHolder {
        public LinearLayout navigationItem;
        public ImageView pathArrow;
        public TextView pathButton;
    }

    private final OnClickListener mHomeNavigationItemClickListener = new OnClickListener() {
        @Override
        public void onClick(View view) {
            if (UiUtils.isValidClick(view.getId())) {
                Activity activity = mFragment.getActivity();
                if (activity instanceof GetMoreSpaceActivity &&
                        !AppConstants.Action.RUN_OPTIMIZE_STORAGE.equals(activity.getIntent().getAction())) {
                    activity.finish();
                } else {
                    int processId = mFragment.getProcessId();
                    NavigationInfo curInfo = NavigationManager.getInstance(processId).getCurInfo();
                    if (curInfo != null) {
                        curInfo.setIsSearchMode(false);
                        AbsMyFilesFragment fragment = curInfo.getCurFragment();
                        if (fragment != null) {
                            fragment.finishActionMode();
                        }
                    }
                    SamsungAnalyticsLog.sendLog(processId, SamsungAnalyticsLog.Event.FOLDER_NAVIGATION, null);
                    MyFilesFacade.goHome(processId, curInfo, mContext);
                }
            }
        }
    };

    private final OnClickListener mNavigationItemClickListener = new OnClickListener() {
        @Override
        public void onClick(View view) {
            if (UiUtils.isValidClick(view.getId())) {
                int index = (Integer) view.getTag();
                int processId = mFragment.getProcessId();
                NavigationInfo info = NavigationManager.getInstance(processId).getCurInfo();
                if (info != null) {
                    AbsMyFilesFragment fragment = info.getCurFragment();
                    if (fragment != null) {
                        fragment.finishActionMode();
                    }
                }
                if (mDisplayedPath.size() > index) {
                    SamsungAnalyticsLog.sendLog(processId, SamsungAnalyticsLog.Event.FOLDER_NAVIGATION, null);
                    MyFilesFacade.executeRecord(processId, mFragment.getActivity(), mDisplayedPath.get(index));
                }
            }
        }
    };

    public void setSplitLandMode(boolean isSplitLandMode) {
        if (AppFeatures.isNote()) {
            mIsSplitLandMode = isSplitLandMode;
            updateForSplitLandMode();
        } else if (AppFeatures.isTabletUIMode()) {
            mIsSplitLandMode = true;
            updateForSplitLandMode();
        }
    }

    private void updateForSplitLandMode() {
        if (!mNavigationItemViewList.isEmpty()) {
            PathIndicatorHolder rootBtn = mNavigationItemViewList.get(0);
            int visibility = needToHideRootPath() || mIsSplitLandMode ? View.GONE : View.VISIBLE;
            mRootPathLayout.setVisibility(visibility);
            rootBtn.pathArrow.setVisibility(visibility);
            if (mIsSplitLandMode && mNavigationItemViewList.size() == 2) {
                rootBtn.navigationItem.setFocusable(true);
            } else {
                rootBtn.navigationItem.setFocusable(false);
            }
        }
    }

    private boolean isGoingParentPath(FileRecord preRecord, FileRecord curRecord) {
        boolean ret = false;
        if (preRecord != null && preRecord.getPath() != null && curRecord != null) {
            ret = preRecord.getPath().equals(curRecord.getFullPath());
        }
        return ret;
    }

    private boolean isGoingToDeepIn(FileRecord preRecord, FileRecord curRecord) {
        boolean ret = true;
        if (preRecord != null && curRecord != null) {
            ret = !preRecord.equals(curRecord);
        }
        return ret;
    }

    @Override
    public void onProgressChanged(String fileName, int progress, int total) {
    }

    @Override
    public void onFinished(boolean bRet, String msg, Bundle extras) {
        MyFilesFacade.execSpinnerProgress(mFragment.mProcessId, mContext, SpinnerProgressCmd.OperationProgress.DISMISS);
    }

    private boolean isSelectedPath(TextView pathButton) {
        PathIndicatorHolder holder = mNavigationItemViewList.get(mNavigationItemViewList.size() - 1);
        return holder.pathButton.equals(pathButton);
    }

    @Override
    public boolean onDrag(View view, DragEvent event) {
        boolean bRet = true;
        TextView pathButton;

        if (view instanceof TextView) {
            pathButton = (TextView) view;
        } else {
            return false;
        }

        Log.d(this, "onDrag on Path Indicator - " + event.getAction());

        switch (event.getAction()) {
            case DragEvent.ACTION_DRAG_STARTED:
                Log.a(this, "ACTION_DRAG_STARTED");
                NavigationInfo curInfo = mFragment.getNavigationInfo();
                if (curInfo != null && FileRecord.StorageType.Category.equals(curInfo.getStorageType())) {
                    bRet = false;
                } else if (event.getClipDescription() != null) {
                    if (!TextUtils.isEmpty(event.getClipDescription().getLabel())) {
                        UiUtils.sendLocalBroadcastIntent(mContext, AppConstants.MYFILES_ACTION_DRAG_AND_DROP_START, -1);
                    }
                }
                break;
            case DragEvent.ACTION_DRAG_ENTERED:
                Log.a(this, "ACTION_DRAG_ENTERED");
                pathButton.setPressed(true);
                pathButton.setTextColor(getResources().getColor(R.color.color_primary_app, null));
                break;
            case DragEvent.ACTION_DRAG_EXITED:
                Log.a(this, "ACTION_DRAG_EXITED");
                pathButton.setPressed(false);
                if (isSelectedPath(pathButton)) {
                    setSelectedItemText(pathButton);
                } else {
                    pathButton.setTextColor(getResources().getColor(R.color.navigation_view_item_text, null));
                }
                break;
            case DragEvent.ACTION_DRAG_ENDED:
                Log.a(this, "ACTION_DRAG_ENDED");
                pathButton.setPressed(false);
                if (isSelectedPath(pathButton)) {
                    setSelectedItemText(pathButton);
                } else {
                    pathButton.setTextColor(getResources().getColor(R.color.navigation_view_item_text, null));
                }
                break;
            case DragEvent.ACTION_DROP:
                Log.a(this, "ACTION_DROP - " + view.getId());
                bRet = doDrop(event.getClipData(), pathButton);
                if (bRet) {
                    UiUtils.sendLocalBroadcastIntent(mContext, AppConstants.MYFILES_ACTION_DRAG_AND_DROP_FINISH, -1);
                }
                break;
        }

        return bRet;
    }

    private boolean doDrop(ClipData clipData, View view) {
        boolean bRet = false;
        FileRecord dstFile = getDstFile(view);

        ClipData.Item item = clipData.getItemAt(0);
        Uri uri = item.getUri();
        if (uri == null) {
            Log.e(this, "clipData uri is null");
            return false;
        }
        if (DragAndDropMgr.checkUserChange(mContext, dstFile, uri)) {
            return true;
        }
        if (dstFile != null) {
            bRet = DragAndDropMgr.canDrop(mContext, clipData, dstFile);
            if (bRet) {
                DragAndDropMgr.convertDragItems(mFragment, mContext, this, clipData, dstFile);
            }
        }
        return bRet;
    }

    private FileRecord getDstFile(View v) {
        int index = 0;
        for (PathIndicatorHolder holder : mNavigationItemViewList) {
            TextView button = holder.pathButton;
            if (button.equals(v)) {
                index = (int) button.getTag();
                break;
            }
        }
        return mDisplayedPath.get(index);
    }

}
